package com.yang.service;

import com.yang.dao.OrderdetailDao;
import com.yang.entity.Orderdetail;
import com.yang.entity.Orders;
import com.yang.dao.OrdersDao;
import com.yang.pojo.OrdersVO;
import com.yang.util.RespEntity;

import java.util.*;

public class OrdersService {
    OrderdetailDao orderDetailDao=new OrderdetailDao();
    OrdersDao orderDao=new OrdersDao();
    //根据用户查询订单和订单详情
    public RespEntity queryByUid(int uid){
        List<Orders> orders = orderDao.queryByUid(uid);
        List<OrdersVO> list=new ArrayList<>();
        for (Orders order : orders) {
            OrdersVO vo=new OrdersVO(order,orderDetailDao.queryByOrderId(order.getId()));
            list.add(vo);
        }
        return new RespEntity(200,"查询订单",list);
    }
    //修改订单状态
    public RespEntity updateByIdandStatus(String id,int status){
        int sum = orderDao.updataStatus(id, status);
        System.out.println("sum"+sum);
        return new RespEntity(200,"修改",sum);
    }
    //后台查询商品订单和详情
    public RespEntity All(int uid){
        List<Orders> orders = orderDao.queryAll(uid);
        List<OrdersVO> list=new ArrayList<>();
        for (Orders order : orders) {
            OrdersVO vo=new OrdersVO(order,orderDetailDao.queryByOrderId(order.getId()));
            list.add(vo);
        }
        return  new RespEntity(200,"查询",list);
    }
    //后台删除
    public RespEntity deleteById(String id){
        int sum = orderDao.deleteById(id);

        return new RespEntity(200,"删除",sum);
    }
}
